﻿using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;

public class BloggingContext : DbContext
{
    //三个实体
    //学校（学校id，班级id，学校名）
    //班级（班级id，学生id，年级）
    //学生（学生id，学生姓名）
    public DbSet<School> Schools { get; set; }
    public DbSet<Class> Classes { get; set; }
    public DbSet<Student> Students { get; set; }
    //log表，记录用户操作
    public DbSet<Log> Logs { get; set; }

    public string DbPath { get; }

    public BloggingContext()
    {
        var folder = Environment.SpecialFolder.LocalApplicationData;
        var path = Environment.GetFolderPath(folder);
        DbPath = System.IO.Path.Join(path, "school-manager.db");
    }

    // The following configures EF to create a Sqlite database file in the
    // special "local" folder for your platform.
    protected override void OnConfiguring(DbContextOptionsBuilder options)
        => options.UseSqlite($"Data Source={DbPath}");
}

public class School
{
    public int SchoolId { get; set; }
    public string SchoolName { get; set; }
    public List<Class> Classes { get; set; } = new();
}
public class Class
{
    public int ClassId { get; set; }
    public int Grade { get; set; }//年级
    public List<Student> Students { get; set; } = new();
    public int SchoolId { get; set; }
}
public class Student
{
    public int StudentId { get; set; }
    public String StudentName { get; set; }
    public int ClassId { get; set; }
}
public class Log
{
    public int LogId { get; set; }
    public string option { get; set; }
}